<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref="search" :config="searchConfig" @search="search" @getHeight="getHeight"/>

    <!-- 操作按钮区域 -->
    <div class="page_table">
      <vxe-grid
        ref="xGrid"
        :border="true"
        :resizable="true"
        :showOverflow="true"
        size="mini"
        :loading="loading"
        :height="pageHeight-seachHeight-94"
        :align="left"
        :columns="columns"
        :data="dataSource"
        :toolbar-config="tableToolbar"
        :checkbox-config="{ trigger: 'row'}"
        @checkbox-change="selectChangeEvent"
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class="table-operator">
            <a-button @click="handleAdd" type="primary">新增</a-button>
            <a-button @click="batchDel" type="primary">删除</a-button>
            <a-button @click="handleAdd" type="primary">导入</a-button>
            <a-button @click="handleAdd" type="primary">导出</a-button>
          </div>
        </template>

        <template #detail="{ row,rowIndex }">
          <a @click="handleDetail(row)">{{ row.giftPoolCode }}</a>
        </template>
        <!-- <template #customerCode='{ row,rowIndex }'>
          <a @click="handleEdit(row, '详情', true, true)">{{ row.customerCode }}</a>
        </template> -->

        <template #action="{ row,rowIndex }">
          <a @click="handleEdit(row)">编辑</a>
          <a-divider type="vertical"/>
          <a href='javascript:' @click='handleBusiness("赠品池",row)'>日志</a>
        </template>
        <template #update="{ row }">
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>
        </template>
        <template #date="{ row,rowIndex }">
          {{ row.createTime }} ~ {{ row.updateTime }}
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync="ipagination.current"
            :page-size.sync="ipagination.pageSize"
            :total="ipagination.total"
            :pageSizes="ipagination.pageSizeOptions"
            @page-change="handlePageChange">
          </vxe-pager>
        </template>
      </vxe-grid>

    </div>
    <!-- table区域-end -->
    <business-log ref="businessLog"></business-log>

    <!-- 表单区域 -->
    <gift-modal ref="modalForm" @ok="modalFormOk"></gift-modal>
  </a-card>
</template>

<script>
import giftModal from './modules/giftModal'
import { PageListMixin } from '@/mixins/PageListMixin'
import Vue from 'vue'
import { getAction } from '@/api/manage'
import search from '@comp/view/base-crud/search/Search'
import { filterObj } from '@/utils/util'

//高级查询modal需要参数

export default {
  name: 'giftList',
  mixins: [PageListMixin],
  components: {
    giftModal,
    search
  },
  // priceAdd
  data() {
    return {
      description: '赠品池',
      //字典数组缓存
      sexDictOptions: [],
      searchConfig: [
        {
          type: 'input',
          name: 'giftPoolCode',
          placeholder: '赠品池编号',
        },
        {
          type: 'input',
          name: 'customerCode',
          placeholder: '经销商编号',
        },
        {
          type: 'input',
          name: 'customerName',
          placeholder: '经销商名称',
        },
        {
          type: 'j-select',
          name: 'status',
          placeholder: '请选择状态',
          dictCode: 'gift_status'
        },],
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      //列定义  表格改这儿
      defColumns: [
        { type: 'checkbox', width: 60, fixed: 'left' },
        {
          title: '赠品池编号',
          align: 'center',
          minWidth: 100,
          field: 'giftPoolCode',
          slots: {
            default: 'detail'
          }
        },
        {
          title: '经销商编号',
          align: 'center',
          minWidth: 100,
          field: 'customerCode'
        },
        {
          title: '经销商名称',
          align: 'center',
          minWidth: 200,
          field: 'customerName'
        },
        {
          title: '所属组织',
          align: 'center',
          minWidth: 120,
          field: 'orgName'
        },
        {
          title: '政策时间',
          align: 'center',
          minWidth: 170,
          field: 'policyDate'
        },
        // {
        //   title: '政策时间',
        //   align: 'center',
        //   minWidth: 120,
        //   field: 'policyDate',
        //   slots: { default: 'date' }
        // },
        {
          title: '赠品编号',
          align: 'center',
          minWidth: 100,
          field: 'goodsCode'
        },
        {
          title: '赠品名称',
          align: 'center',
          minWidth: 200,
          field: 'goodsName'
        },
        {
          title: '赠品总金额',
          align: 'center',
          minWidth: 100,
          field: 'goodsAmount'
        },
        {
          title: '已使用金额',
          align: 'center',
          minWidth: 100,
          field: 'useAmount'
        },
        {
          title: '剩余金额',
          align: 'center',
          minWidth: 100,
          field: 'surplusAmount'
        },
        {
          title: '批次日期',
          align: 'center',
          minWidth: 170,
          field: 'batchDate'
        },
        {
          title: '备注',
          align: 'center',
          minWidth: 200,
          field: 'remarks'
        },
        {
          title: '创建人',
          align: 'center',
          minWidth: 100,
          field: 'createName'
        },
        {
          title: '创建时间',
          align: 'center',
          minWidth: 150,
          field: 'createTime'
        },
        {
          title: '更新人',
          align: 'center',
          minWidth: 100,
          field: 'updateName'
        },
        {
          title: '更新时间',
          align: 'center',
          minWidth: 150,
          field: 'updateTime'
        },
        {
          title: '状态',
          align: 'left',
          field: 'status',
          fixed: 'right',
          minWidth: 80,
          slots: { default: 'update' }
        },
        {
          title: '操作',
          width: 150,
          fixed: 'action',
          align: 'center',
          fixed: 'right',
          slots: { default: 'action' }
        },
      ],
      url: {
        list: window._CONFIG['domianPromotion'] + '/giftpool/dmsGiftPool/findPageList',
        detail: window._CONFIG['domianPromotion'] + '/giftpool/dmsGiftPool/getInfo',
        delete: window._CONFIG['domianPromotion'] + '/giftpool/dmsGiftPool/delete',
        startOrStopUrl: window._CONFIG['domianPromotion'] + '/giftpool/dmsGiftPool/updateStatus',
        deleteBatch: window._CONFIG['domianPromotion'] + '/giftpool/dmsGiftPool/deleteBatch',
        exportXlsUrl: '/test/cn-formDemo/exportXls'
      }
    }
  },
  methods: {
    handleAdd() {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增赠品池'
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.disableEdit = false
    },
    handleEdit: function (row) {
      this.$refs.modalForm.edit(row)
      this.$refs.modalForm.title = '编辑赠品池'
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.disableEdit = true //编辑不能修改

    },
    getQueryParams() {
      //高级查询器
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)

      param.field = this.getQueryField()
      param.current = this.ipagination.current
      param.size = this.ipagination.pageSize
      delete param.birthdayRange //范围参数不传递后台
      return filterObj(param)
    },
    initColumns() {
      //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
      //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

      var key = this.$route.name + ':colsettings'
      let colSettings = Vue.ls.get(key)
      if (colSettings == null || colSettings == undefined) {
        let allSettingColumns = []
        this.defColumns.forEach(function (item, i, array) {
          allSettingColumns.push(item.dataIndex)
        })
        this.settingColumns = allSettingColumns
        this.columns = this.defColumns
      } else {
        this.settingColumns = colSettings
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.dataIndex == 'action') {
            return true
          }
          if (colSettings.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols
      }
    }
  },
  created() {
    this.initColumns()
  }

}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>